<%--
  Created by IntelliJ IDEA.
  User: 许正雄
  Date: 2021/12/12
  Time: 18:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台管理</title>
    <link type="text/css" rel="stylesheet" href="/static/css/style.css" />
    <script type="text/javascript" src="/static/scripts/function-manage.js"></script>
    <script type="text/javascript"src="/static/jquery3.6.0.js"></script>
</head>
<body>
<%@include file="/manage/head.jsp"%>
<div id="position" class="wrap">
    您现在的位置：管理后台
</div>
<div id="main" class="wrap">
    <%@include file="/manage/left.jsp"%>
    <div class="main">
        <h2>新闻管理</h2>
        <div>
            <form action="/manage/selectNewsPage" id="frm" method="post">
                <input type="hidden" id="pageNo"  name="pageNo" value="${newsPage.current}"/>
                <input type="hidden" id="pageSize" name="pageSize" value="${newsPage.size}"/>
                新闻标题：<input type="text" name="title" value="${news.title}"/>
                新闻内容：<input type="text" name="news" value="${news.news}"/>
                <input type="submit" value="查询"/>
            </form>
        </div>
        <div class="manage">
            <table class="list">
                <tr>
                    <th>ID</th>
                    <th>新闻标题</th>
                    <th>新闻内容</th>
                    <th>描述</th>
                    <th>操作</th>
                </tr>
                <c:forEach items="${newsPage.records}" var="news" varStatus="vs">
                    <tr>
                        <td class="first w4 c">${vs.index+1}</td>
                        <td>${news.title}</td>
                        <td>${news.news}</td>
                        <td>${news.remark}</td>
                        <td class="w1 c"><a href="queryNewsById?id=${news.id}" >修改</a> <button onclick="DeleteNews('${news.strId}')" type="button" id="del" >删除</button></td>
                    </tr>
                </c:forEach>
                <tfoot>
                   <tr>
                       <td colspan="8">
                           每页：<select name="size" id="spageSize">
                                    <option value="3" <c:if test="${newsPage.size==3}">selected</c:if>>3</option>
                                    <option value="5" <c:if test="${newsPage.size ==5}">selected</c:if>>5</option>
                                    <option value="8" <c:if test="${newsPage.size==8}">selected</c:if>>8</option>
                                    <option value="10" <c:if test="${newsPage.size==10}">selected</c:if>>10</option>
                                </select>行&nbsp;&nbsp;&nbsp;&nbsp;
                           <a href="javascript:goToPage(1)">首页</a>
                           <c:if test="${newsPage.hasPrevious()}">
                               <a href="javascript:goToPage(${newsPage.current-1})">上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
                           </c:if>
                           <c:if test="${!newsPage.hasPrevious()}">
                               <a href="javascript:alert('已经是第一页了！')">上一页</a>&nbsp;&nbsp;&nbsp;
                           </c:if>
                           <c:if test="${newsPage.hasNext()}">
                               <a href="javascript:goToPage(${newsPage.current+1})">下一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
                           </c:if>
                           <c:if test="${!newsPage.hasNext()}">
                               <a href="javascript:alert('已经是最后一页了！')">下一页</a>&nbsp;&nbsp;&nbsp;
                           </c:if>
                           <a href="javascript:goToPage(${newsPage.pages})">末页</a>&nbsp;&nbsp;&nbsp;&nbsp;
                           &nbsp;&nbsp;&nbsp;&nbsp;第${newsPage.current}页/共${newsPage.pages}页
                       </td>
                   </tr>
                </tfoot>
            </table>
        </div>
    </div>
    <div class="clear"></div>
</div>
<div id="footer">

</div>
</body>
<script>
    function DeleteNews(d) {
            let msg="确认是否删除该信息？";
            if (confirm(msg)==true){
                $.ajax({
                    url:"/manage/deleteNews",
                    type:"post",
                    data:"id="+d,
                    success:function (ret) {
                        if (ret * 1 === 1){
                            alert("删除成功!!!");
                            $(location).attr("href","../manage/selectNewsPage");
                        }else if(ret === 0) {
                            alert("删除失败！")
                            $(location).attr("href","../manage/selectNewsPage");
                        }

                    }
                })
                return true;
            }else {
                return false;
            }
    }
    function goToPage(ret) {
        $("#pageNo").val(ret);
        $("#frm").submit();
    }
    $(function () {
        $("#spageSize").change(function () {
            $("#pageSize").val($(this).val());
            $("#pageNo").val(1);
            $("#frm").submit();
        })
    })
    function cl() {//设定每次查询第一页
        $("#pageNo").val(1);
    }
</script>
</html>

